package com.sxz.sbs.module.home.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sxz.sbs.R;
import com.sxz.sbs.module.home.bean.HomeBean;

import java.util.List;

/**
 * 首页列表适配器
 */

public class HomeAdapter extends BaseQuickAdapter<HomeBean.AuthListBean,BaseViewHolder>{
    public HomeAdapter(@Nullable List<HomeBean.AuthListBean> dataList) {
        super(R.layout.item_home_layout,dataList);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeBean.AuthListBean item) {
        helper.setText(R.id.tv_item_home_name,item.getTxt_Name());
        helper.setText(R.id.tv_item_home_intro,item.getTxt_Description());
        helper.setImageResource(R.id.iv_item_home,getDrawableId(item.getIc_Path()));
        if (item.getIsRed() == 1) {
            helper.setVisible(R.id.iv_red_dot,true);
        } else {
            helper.setVisible(R.id.iv_red_dot,false);
        }
    }
    private int getDrawableId (String name) {
        try {
            return mContext.getResources().getIdentifier(name, "drawable", mContext.getPackageName());
        }catch (Exception e) {
            return mContext.getResources().getIdentifier("ic_staff", "drawable", mContext.getPackageName());
        }
    }
}
